package com.haotunet.app.goldtreasure.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

/**
 * 存储数据到手机内存中使用的类
 */
public class ShareStore {
	private static String INIT_DATA = "prefs";

	public SharedPreferences mSharedPreferences = null;

	public Editor mEditor = null;

	public ShareStore(Context context, String name, int mode) {
		mSharedPreferences = context.getSharedPreferences(name, mode);
		mEditor = mSharedPreferences.edit();
	}

	public ShareStore(Context context) {
		this(context, INIT_DATA, 0);
	}

	public void putString(String key, String value) {
		mEditor.putString(key, value);
		
	}

	public String getString(String key, String defaultValue) {
		return mSharedPreferences.getString(key, defaultValue);
	}

	public void putInt(String key, int value) {
		mEditor.putInt(key, value);
	}

	public int getInt(String key, int defaultValue) {
		return mSharedPreferences.getInt(key, defaultValue);
	}

	public void putFloat(String key, float value) {
		mEditor.putFloat(key, value);
	}

	public float getFloat(String key, float defaultValue) {
		return mSharedPreferences.getFloat(key, defaultValue);
	}

	public void putLong(String key, long value) {
		mEditor.putLong(key, value);
	}

	public long getLong(String key, long defaultValue) {
		return mSharedPreferences.getLong(key, defaultValue);
	}

	public void putBoolean(String key, boolean value) {
		mEditor.putBoolean(key, value);
	}

	public boolean getBoolean(String key, boolean defaultValue) {
		return mSharedPreferences.getBoolean(key, defaultValue);
	}

	public void remove(String key) {
		mEditor.remove(key);
	}

	public void commit() {
		mEditor.commit();
	}

	public void clear() {
		mEditor.clear().commit();
	}

}
